package com.bwie.service;

import com.bwie.bean.Canteen;
import com.bwie.bean.City;
import com.bwie.bean.Food;
import com.bwie.bean.User;
import com.bwie.dao.CanteenDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CanteenServiceImpl implements CanteenService {

    @Autowired
    CanteenDao canteenDao;

    @Override
    public List<Canteen> list(Map map) {
        return canteenDao.list(map);
    }

    @Override
    public List<Food> listFood() {
        return canteenDao.listFood();
    }

    @Override
    public List<City> listCity(Integer pid) {
        return canteenDao.listCity(pid);
    }

    @Override
    public int add(Canteen canteen, Integer[] fids) {
        int a=canteenDao.addCanteen(canteen);
        Map map = new HashMap();
        map.put("cid",canteen.getCid());
        map.put("fids",fids);
        canteenDao.addCf(map);
        return a;
    }

    @Override
    public int del(Integer cid) {
        int a=canteenDao.delCanteen(cid);
        canteenDao.delCf(cid);
        return a;
    }

    @Override
    public int dels(String cid) {
        int a=canteenDao.delCanteens(cid);
        canteenDao.delCfs(cid);
        return a;
    }

    @Override
    public int update(Canteen canteen, Integer[] fids) {
        int a=canteenDao.update(canteen);
        canteenDao.delCf(canteen.getCid());
        Map map = new HashMap();
        map.put("cid",canteen.getCid());
        map.put("fids",fids);
        canteenDao.addCf(map);
        return a;
    }

    @Override
    public Canteen listHui(Integer cid) {
        return canteenDao.listHui(cid);
    }

    @Override
    public User listUser(User user) {
        return canteenDao.listUser(user);
    }
}
